<?php

namespace app\api\controller\manage;

use app\admin\model\AdminLog;
use app\common\controller\Api;
use app\common\exception\UploadException;
use app\common\library\Auth;
use app\common\model\Attachment;
use think\Config;
use think\Db;
use think\Hook;
use think\Request;
use think\File;
use think\Session;
use think\Validate;

/**
 * 首页接口
 */
class Login extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function login()
    {
        $code='xingkangzhihuishiji';
        if ($this->request->isPost()) {
            $mobile = $this->request->param('mobile');

            if (empty($mobile)) {
                $this->error('请输入账号');
            }
            $info = Db::name('admin')->field('id,username,nickname,salt,avatar,mobile')->where(array('mobile' => $mobile, 'status' => 'normal'))->find();
            if (!$info) {
                $this->error('该账号不存在');
            }
            $password = $this->request->param('password');
            if (empty($password)) {
                $this->error('请输入密码');
            }
            $password = md5(md5($password) . $info['salt']);
            $info = Db::name('admin')->field('mobile')->where(array('mobile' => $mobile, 'password' => $password, 'status' => 'normal'))->find();
            if (!$info) {
                $this->error('密码错误');
            }
            $token = hash('sha256', $code);
            $info['token'] = $token;
        } else {
            $this->error('非法请求');
        }
        $this->success('请求成功', $info);
    }
}